<?php
class M_rooms extends CI_Model{
	
	function get_all_rooms(){
		$query = $this->db->get('rooms');
		return $query->num_rows() > 0 ? $query->result() : FALSE;
	}	
	
	function get_room($room_id){
		$query = $this->db->where('room_id', $room_id)->get('rooms');	
		return $query->num_rows() > 0 ? $query->row() : FALSE;
	}
	
	function add_room($v){
		$data = array(
			'code' => $v->code,
			'name' => $v->name,
			'description' => $v->description,
			'created' => NOW
		);
		
		$this->db->insert('rooms', $data);
		return $this->db->affected_rows() > 0 ? TRUE : FALSE;
	}
	
	function edit_room($v){
		$data = array(
			'code' => $v->code,
			'name' => $v->name,
			'description' => $v->description,
			'updated' => NOW
		);
		
		$this->db->where('room_id', $v->room_id)->update('rooms', $data);
		return $this->db->affected_rows() > 0 ? TRUE : FALSE;
		
	}
	
	function delete_room($room_id){
		$this->db->delete('rooms', array('room_id' => $room_id));
		return $this->db->affected_rows() > 0 ? TRUE : FALSE;
	}
}

?>